package com.shop.dingdongshoppingapi.controller;


import com.shop.dingdongshoppingapi.dto.LikeToCarDto;
import com.shop.dingdongshoppingapi.dto.ShopCarAddDto;
import com.shop.dingdongshoppingapi.entity.ShopCar;
import com.shop.dingdongshoppingapi.service.intf.ShopCarService;
import com.shop.dingdongshoppingapi.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


/*
    @author:张郢龙
    @date:2022/7/1 16:12
    @Description:
*/

@Api("购物车接口")
@RestController
@CrossOrigin
@RequestMapping("/api/shopcar")
public class ShopCarController {
	@Resource
	private ShopCarService service;
	/*
	* 检查登录用户购物车的所有订单*/
	@GetMapping("checkShopCar.do")
	@ApiOperation("查询购物车所有订单")
	public R checkShopCar(HttpServletRequest request){
		return service.checkShopCar(request.getIntHeader("ddstoken"));
	}

	@PostMapping("delShopById.do")
	@ApiOperation("删除购物车的商品")
	public R delShopById(int id){
		return service.delShopById(id);
	}

	@GetMapping("fourRandom.do")
	@ApiOperation("四个随机的猜你喜欢")
	public R fourRandom(){
		return service.fourRandom();
	}

	@PostMapping("addLikeToCar.do")
	@ApiOperation("在猜你喜欢往购物车添加订单")
	public R addLikeToCar(@RequestBody LikeToCarDto likeToCarDto, HttpServletRequest request){
		return service.addLikeToCar(likeToCarDto,request.getIntHeader("ddstoken"));
	}

	@PostMapping("updateShopCarNum.do")
	@ApiOperation("改变数据库商品数量")
	public R updateShopCarNum(@RequestBody ShopCar shopCar){
		return service.updateShopCarNum(shopCar);
	}

	@PostMapping("/add.do")
	@ApiOperation("添加商品到购物车")
	public R add(@RequestBody ShopCarAddDto addDto, HttpServletRequest request){

		return service.add(addDto, request.getIntHeader("ddstoken"));
	}



}
